
public class RandomImmigrants {
	
	public static Chromo[] performRandomImmigrants(Chromo[] members)
	{
		
		int replacement = members.length/2;
		
		mergeSort_srt(members,0,members.length -1);
		
		for(int i = members.length -1;i > members.length-replacement;i--)
		{
			members[i] = new Chromo();
		}
		return members;
	}
	
	//sorts from low to high, lower = better
	public static void mergeSort_srt(Chromo[] array,int lo, int n){
	
		int low = lo;
		int high = n;
		
		if (low >= high) {
		    return;
		}

		int middle = (low + high) / 2;
		mergeSort_srt(array, low, middle);
		mergeSort_srt(array, middle + 1, high);
		int end_low = middle;
		int start_high = middle + 1;
		
		while ((lo <= end_low) && (start_high <= high)) {
			if (array[low].rawFitness < array[start_high].rawFitness) {
				low++;
		    } else {
		    	double Temp = array[start_high].rawFitness;
		    	for (int k = start_high- 1; k >= low; k--) {
		          array[k+1] = array[k];
		        }
		                array[low].rawFitness = Temp;
		                low++;
		                end_low++;
		                start_high++;
		     }
		}
	}  
}
